﻿using System;
using System.Collections.Generic;
using ComponentFactory.Krypton.Toolkit;
using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Nuwanda.Common;
using Nuwanda.TfsSpotlight.Data;
using StructureMap;

namespace Nuwanda.TfsSpotlight.Views.CreateWorkItem
{
    [Author("Bartłomiej Legiędź")]
    [Pluggable("CreateWorkItemView")]
    public partial class CreateWorkItemView : KryptonForm, ICreateWorkItemView
    {
        private ICreateWorkItemPresenter _presenter;

        public CreateWorkItemView()
        {
            InitializeComponent();
        }

        public void AttachPresenter(ICreateWorkItemPresenter presenter)
        {
            this._presenter = presenter;
        }

        public List<ServerDescriptor> DataSource
        {
            set { this.bsServers.DataSource = value; }
        }

        public WorkItemType GetSelectedType()
        {
            return this.lbTypes.SelectedItem as WorkItemType;
        }

        public ServerDescriptor GetSelectedServer()
        {
            return this.lbServers.SelectedItem as ServerDescriptor;
        }

        public void SelectServer(ServerDescriptor server)
        {
            this.lbServers.SelectedItem = server;
        }

        public void SelectProject(ProjectDescriptor project)
        {
            this.lbProjects.SelectedItem = project;
        }

        public void SelectWorkItemType(WorkItemType workItemType)
        {
            this.lbTypes.SelectedItem = workItemType;
        }

        public bool EnableCreate
        {
            set { this.btnCreate.Enabled = value; }
        }


        private void RefreshHandler(object sender, EventArgs e)
        {
            this._presenter.HandleRefresh();
        }

        private void SelectedTypeChangedHandler(object sender, EventArgs e)
        {
            this._presenter.HandleSelectedTypeChanged();
        }

        private void CreateHandler(object sender, EventArgs e)
        {
            this._presenter.HandleCreate();
        }
    }
}
